package com.hiltony.web.serviceImpl;

import com.hiltony.web.mapper.UserInfoMapper;
import com.hiltony.web.model.UserInfo;
import com.hiltony.web.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.xml.registry.infomodel.User;
import java.util.List;

/**
 * Created by YX on 2016/9/11.
 */

@Service("userService")
public class UserServiceImpl implements UserService {

    @Resource
    private UserInfoMapper userInfoMapper;

    @Override
    public UserInfo getUser(UserInfo userInfo){
        return userInfoMapper.getUserInfo(userInfo);
    }
    @Override
    public UserInfo getUserById(int id) {
        return userInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<UserInfo> getUsers(UserInfo userInfo) {
        return userInfoMapper.getUserList(userInfo);
    }

    @Override
    public int insert(UserInfo userInfo) {
        UserInfo tmp = new UserInfo();
        tmp.setUserName(userInfo.getUserName());
        if (userInfoMapper.getUserInfo(tmp)!=null){
            throw new RuntimeException("账户名不得重复");
        }
        else {
            return userInfoMapper.insertUser(userInfo);
        }
    }

    @Override
    public int updateUser(UserInfo userInfo) {
        return userInfoMapper.updateUser(userInfo);
    }
}
